#### Start of system configuration section. ####


srcdir =	@srcdir@

ifeq ($(srcdir),.)
srcdir = ..
endif

VPATH :=	$(srcdir)

# Common prefix for machine-independent installed files.
prefix =	@prefix@

# Common prefix for machine-dependent installed files.
exec_prefix =	@exec_prefix@

bindir =	$(exec_prefix)/bin
libdir =	$(exec_prefix)/Sys/libs

INSTALL =	@INSTALL@
INSTALL_DATA =	@INSTALL_DATA@

CC =		@CC@

CFLAGS =	@CFLAGS@
LDFLAGS =	@LDFLAGS@

RANLIB =	@RANLIB@
AR =		ar

#### End system configuration section ####

# I *love* GNU make!
define catenate
/bin/echo -n creating $@...
/bin/echo "$(^:%=#include \"%\"\n)" >$@
/bin/echo done
endef

FLAVOR_CFLAGS = -m$(CPU) -m$(FPU)
OTHER_CFLAGS =	-fomit-frame-pointer
ALL_CFLAGS =	$(CFLAGS) $(FLAVOR_CFLAGS) $(OTHER_CFLAGS) -g $(INCS) $(DEFS)

INCS =		-I$(srcdir) -I$(srcdir)/../library -I$(srcdir)/../include -I.
DEFS =		-D__DBINTERFACE_PRIVATE
LIB =		libixnet.a
SHELL = 	sh

# Strip the executable (-s), don't look for standard libraries (-nostdlib)
# don't link in crt0.o (-nostartfiles)
# link in some libc.a files (-L../../glue/no-baserel -lglue)
# need some stuff in libgeneral.a

LINKFLAGS =	-nostdlib -nostartfiles -L../../glue/no-baserel -L../../db/no-baserel

.s.o:
		cp $< x.c
		$(CC) $(ALL_CFLAGS) -traditional -E x.c -o x.s
		$(CC) $(ALL_CFLAGS) -c x.s -o $@
		rm -f x.c x.s

.c.o:
		$(CC) $(ALL_CFLAGS) -c $< -o $@

all: ixnet.library ixnet.debug

SRC_A4 =	set_errno.c siglaunch.c
SRC_MISC =	create_header.c parse_version.c

SRC =           $(filter-out $(SRC_A4) $(SRC_MISC),$(notdir $(wildcard $(srcdir)/*.c)))

OBJ_OTHERS =	version.o

OBJ_N = 	start.o

IXLIBS =	$(LIB)

LIBS =		-lglue


$(LIB) :        a4.o az.o $(OBJ_OTHERS)
		rm -f $@
		$(AR) rv $@ $^
		$(RANLIB) $@

ixnet.library:	$(OBJ_N) $(IXLIBS)
		$(CC) -s $(LINKFLAGS) $(OBJ_N) $(IXLIBS) $(LIBS) -o $@

ixnet.debug:	$(OBJ_N) $(IXLIBS)
		$(CC) -g $(LINKFLAGS) $(OBJ_N) $(IXLIBS) $(LIBS) -o $@

clean:
		rm -rf 680?0

clobber:	clean
		rm -f Makefile

a4.o:		a4.c
		$(CC) $(ALL_CFLAGS) -ffixed-a4 -c $< -o $@

start.o:	$(srcdir)/start.s version.h $(srcdir)/../include/sys/ixnet_syscall.def ix_internals.h

version.o:	version.c

a4.c:		$(SRC_A4)
		@$(catenate)

az.c:		$(SRC)
		@$(catenate)

ix_internals.h: create_header
		./create_header >$@

create_header:	create_header.o

create_header.o:	create_header.c $(srcdir)/../include/user.h ixnet.h

parse_version:	parse_version.o

version.h version.c:	parse_version ../version.in
			./parse_version $(srcdir)
